-
Notifications
You must be signed in to change notification settings - Fork 837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CycledLeScanner : a version scanning when screen turns on or off #450
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR, @OPscT. These are interesting ideas, and the addition of extra scanning on screen change is a good one. Any chance you can provide more details on the test conditions that led you to conclude "we get better scanning result (and faster beacons detection) if an application scans 1s or 6s during 30s than when scanning one time for 30s"? I would be curious to know the device model/OS version used to see this, the beacon transmission rate, and the difference in the detection time when using this technique. |
We observe on all the devices we test from Android 4.3 to Android 7 that when a device scans for a long period (for exemple 30s.) the result of scan is delivered at the end of the scan period when using the AltBeacon library.
We did additional test today. We think the problem can come from the AltBeacon library delivery process.
With this app, devices detect entry and exit of our beacons immediately when scanning for 30s. |
@OPscT, I believe this is working as designed. The detected beacons are generally delivered at the end of the scan cycle, except when the scan cycle is long and the detection causes a new entry condition, in which case they are delivered immediately to avoid a long detection delay. |
Ok I see and looking deeper to the code I get a better understanding of the delivery process (the staff done in the "onCycleEnd" method from the CycledLeScanCallback class and the "processFromScan" method). So with these informations, the "ActiveScanPeriods" seems useless and we will remove it. Do you agree? |
@OPscT, yes, this may explain your observation that "we notice that we get better scanning result (and faster beacons detection) if an application scans 1s or 6s during 30s than when scanning one time for 30s." This would happen if beacons are already detected recently, so results would not get delivered until the end of the scan cycle. |
Very good PR, thank you! I think this is a very good feature that is important to add. Aside from the comments above, my only reluctance to merge right away is out of concern over this creating hard to track down bugs. There are lots of code changes here — over 1000 lines, and this is probably the most complex part of the library. I am not fully confident that after reviewing it that the changes haven’t created little problems. Unfortunately, unit test coverage of this section of code is pretty much non-existent. (Although splitting out the LeScanner from the CycledLeScanner would make adding test coverage easier by being able to have a mock LeScanner for unit tests.) A few general questions and comments:
|
|
@OPscT, to answer your question about Read here for more info: #414 |
Merge done. I did tests on Samsung S3 - Android 4.4, S4 - Android 5.0.1, S5 - Android 6.0.1, and Nexus 5 plus - Android 7.0 It seems ok for me. I let you cross check. |
Thanks, @OPscT, I'll take a look. |
@OPscT, In testing today with the reference app on my Nexus 5X, I am seeing that background scanning continues continually after putting the app to the background. I would expect a 30 second duty cycle on scans. See log below, and note that the scan cycle doesn't stop after putting the app to the background. You always see "Waiting to stop scan cycle for another 1000 milliseconds". I don't think this is right. Do you see this, too?
|
I think you did not test with the last version. This problem was solved in the commit and I re-check this morning: It works correctly from me. |
@OPscT, I'm sorry this has been left open for so long. I really like this feature and would like to see it part of the library. Two issues have come up since this was submitted that prevent this from being merged as-is:
|
Hello David, I am back,
|
Hi, @OPscT. Yes, it would be possible to trigger an immediate ScanJob through a message received by a broadcast receiver. This would be a relatively minor change to the As to your other point, "About the getCycledLeScanner/setCycledLeScanner methods, a possibility is to use reflexion...." Is this even necessary? I'd really like to see screen-on scanning be automatic without having to configure a special version of CycledLeScanner. It doesn't seem there is a good reason not to do this. |
Hi David, I get the point that you would like the "Screen Turns Off / Screen Turns On" scanning feature integrated as default to the CycledLeScanner. I would like to get the possibility to configure the CycledLeScanner to develop different background scanning strategies. About the way to register the "Screen On/ Screen Off" action on Android O: I don't think to launch a JobScheduler when BroadcastReceiver receives a screen action. The broadcast screen action must be registered and unregistered manually.
Whatever, I can start to integrate the Screen Turns Off / On to the default CycledLeScanner to permit a merge. |
When the The only difference in the screen on/off case is that the As to the other point "I think to strategies based on beacon density: if I summarize, the background scan is higher when it's an area with high beacon density with a user is moving than when it's an area with few beacons or no beacons at all." We should probably discuss this in a new Github issue. Although it is related, I would like to keep the change separate if possible. I'd also like to understand more why higher beacon densities would benefit from a different scanning strategy -- it isn't obvious to me immediately why this is true. |
I get your point. I haven't noticed the immediate scan job. Ok to discuss later on a new issue about the possibility of other scanning strategies. |
Close as fixed by #941 ? |
This PR permits to create new CycledScanner strategies.
It comes with a new CycledScanner strategy, the CycledScannerScreenState class, that scans for beacons only when screen turns on or turn off.
We split the CycledLeScanner class in two classes:
We introduce the notion of "ScanPeriods" for an easiest management of the "scanPeriod" and the "betweenScanPeriod"
We will be glad to get your feedbacks,
Regards,
Olivier